#include "ReceiverEngine.h"
#include <thread>
#include "Logger.h"
#include "OnTestMsg.h"
#include "XnccType.h"
using namespace std::placeholders;
using namespace xncc::user;
using namespace xncc::types;

ReceiverEngine::ReceiverEngine(int id) : EventEngine(id), engineId_(id)
{
}

void ReceiverEngine::init()
{
    auto testFunc = std::bind(&ReceiverEngine::handleTestMsg, this, _1, _2, _3, _4);
    registerUserFunc(MessageTraits<OnTestMsg>::ID, testFunc);
    registerUserFunc(MessageTraits<NewTestMsg>::ID, testFunc);
}

void ReceiverEngine::handleTestMsg(const char* msg, uint32_t len, thread_id_t tid, connection_id_t connId)
{
    LOG_INFO(CONSOLE_LOG) << "engine " << engineId_
                          << " receive msg = " << std::string(msg, static_cast<std::size_t>(len));
}
